const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const formatPrice = (price)=>{
  return (price / 100).toFixed(2)
}

const startWith = (src, str)=> {
  const reg = new RegExp('^' + str)
  return reg.test(src)
}

const endWith = (src, str) => {
  const reg = new RegExp(str + '$')
  return reg.test(src)
}
function loginNow() {
  let userInfo = wx.getStorageSync('token');
  if (userInfo == '') {
      wx.navigateTo({
          url: '/pages/app-auth/index',
      });
      return false;
  } else {
      return true;
  }
}
// export const host = 'http://linjiashop-mobile-api.microapp.store/'
export const host = 'http://10.0.3.104:8081/'
export const fileMgrUrl = host + 'file/getImgStream?idFile='
module.exports = {
  formatTime: formatTime,
  startWith,
  endWith,
  formatPrice,
  fileMgrUrl,
  loginNow
}
